//
//  HZOAuthModel.swift
//  weibo002
//
//  Created by 黑眼圈 on 16/4/19.
//  Copyright © 2016年 heiyan. All rights reserved.
//

import UIKit

class HZOAuthModel: NSObject,NSCoding {
    
    
    
    var access_token:String?
    
    //当获取到了网络上的access_token的可使用时间时,就立马计算出过期的时间
    var expires_in:Int = 0 {
        
        didSet{
  
           expirationDate = NSDate(timeIntervalSinceNow: Double(expires_in))
        }
    }
    
    var remind_in:String?
    var uid:String?
    
    var name:String?
    var profile_image_url:String?
    
    
    //记录access_token过期的时间
    var expirationDate:NSDate?
    
    
    
    //KVC构造方法
    init(dict:[String:AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    
    // MARK: -  归档和反归档的方法
    required init?(coder aDecoder: NSCoder) {
        
        name = aDecoder.decodeObjectForKey("name") as? String
        profile_image_url = aDecoder.decodeObjectForKey("profile_image_url") as? String
        uid = aDecoder.decodeObjectForKey("uid") as? String
        remind_in = aDecoder.decodeObjectForKey("remind_in") as? String
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expires_in = aDecoder.decodeIntegerForKey("expires_in")
        expirationDate = aDecoder.decodeObjectForKey("expirationDate") as? NSDate
        
    }
    
    //归档
    func encodeWithCoder(aCoder: NSCoder) {
        
        
        aCoder.encodeObject(name, forKey: "name")
        aCoder.encodeObject(profile_image_url, forKey: "profile_image_url")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(remind_in, forKey: "remind_in")
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeInteger(expires_in, forKey: "expires_in")
        aCoder.encodeObject(expirationDate, forKey: "expirationDate")
    }

}
